﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreFrame.Business;
using CoreFrame.Core.Orm;
using MarchEstate.Manager.BusinesEntity;

namespace MarchEstate.Manager.Dao.Init
{
    public class BaseDataDao : AbstractDao
    {
        public System.Data.DataTable GetBaseDic(int type)
        {
            string strSql = "select Code ,TypeName as Name from WY_BaseDic where StandType="+type;
            return oleDb.GetDataTable(strSql);
        }

        private List<AbstractBaseData> getbasedata(string strsql)
        {
            List<AbstractBaseData> baselist = new List<AbstractBaseData>();
            AbstractBaseData basedata = null;
            System.Data.IDataReader read = oleDb.GetDataReader(strsql);
            while (read.Read())
            {
                basedata = NewObject<AbstractBaseData>();
                basedata.Code = read["Code"].ToString();
                basedata.Name = read["Name"].ToString();
                baselist.Add(basedata);
            }
            read.Close();
            read.Dispose();
            return baselist;
        }

        public List<AbstractBaseData> GetAreaList()
        {
            string strsql = @"SELECT  AreaCode as Code, AreaName as Name FROM  WY_Area";
            return getbasedata(strsql);
        }

        public List<AbstractBaseData> GetBuildList(string areacode)
        {
            string strsql = @"SELECT  BuildingCode as Code, BuildingName as Name FROM  WY_Building where  (AreaCode = '{0}')";
            strsql = string.Format(strsql, areacode);
            return getbasedata(strsql);
        }

        public List<AbstractBaseData> GetStatItem()
        {
            string strsql = @"SELECT  Code, statname as Name FROM  WY_StatItem";
            //strsql = string.Format(strsql, areacode);
            return getbasedata(strsql);
        }
    }
}